
"""开始执行接口自动化，项目工程部署完毕后直接运行该文件即可"""
"""FLASK框架"""
import os

import requests
from flask import *

app = Flask(__name__)
@app.route('/')
def index():
    return render_template("login.html")

@app.route('/upload',methods=['POST'])
def up():
    basedir = os.path.dirname(__file__)
    img = request.files.get('photo')
    path = basedir + '/static/images/'
    file_path = path + img.filename
    img.save(file_path)
    print("basedir: " + basedir)
    print("file_path: " + file_path)
    return render_template('success.html',temp_img = img.filename)

@app.route('/login',methods=['POST'])
def login():
    user = request.values.get('user')
    pwd = request.values.get('pwd')
    if user and pwd:
        if user == 'admin' and pwd == '123456':
            res = {"code": 200, "message": "登录成功"}
        else:
            res = {"code": -1, "message": "帐号密码错误"}
    else:
        res = {"code": 10001, "message": "参数不能为空"}
    res1 = json.dumps(res,ensure_ascii=False)
    #return render_template('result.html',result = resu1)
    return res1

if __name__ == '__main__':
    app.run()
